package restaurant.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import restaurant.dao.CuisineDao;
import restaurant.pojo.FoodsType;
import restaurant.utils.BaseDao;

public class CuisineDaoImpl extends BaseDao implements CuisineDao {

	@Override
	public int addCuisine(String type) throws SQLException {
		String sql = "insert into foodstype values(null,?)";
		int i = qr.update(sql, type);
		return i;
	}

	@Override
	public List<FoodsType> showCuisine() throws SQLException {
		String sql = "select * from foodstype order by id";
		List<FoodsType> types = qr.query(sql, new BeanListHandler<FoodsType>(FoodsType.class));
		return types;
	}

	@Override
	public int updateCuisine(String id,String type) throws SQLException {
		String sql = "update foodstype set type=? where id = ?";
		int i = qr.update(sql, type,id);
		return i;
	}

	@Override
	public int deleteCuisine(String id) throws SQLException {
		String sql = "delete from foodstype where id = ?";
		int i = qr.update(sql, id);
		return i;
	}

	@Override
	public List<FoodsType> find(String param) throws SQLException {
		param = "%"+ param +"%";
		String sql = "select * from foodsType where type like ?";
		List<FoodsType> type = qr.query(sql, new BeanListHandler<FoodsType>(FoodsType.class), param);
		return type;
	}

}
